//import java.util.Scanner;

import javax.swing.JOptionPane;

public class Challenge5
{
	
	public static void main(String[] args)
	{
		//Scanner input = new Scanner(System.in);
		String operation = "";
		while ((!operation.equals("q")) && (!operation.equals("Q")))
		{
			if ((!operation.equals("q")) && (!operation.equals("Q")))
			{
				String num1str = JOptionPane.showInputDialog("Enter your first number.");;
				try
				{
					Double num1 = Double.parseDouble(num1str);
				}
				catch(Exception e)
				{
					JOptionPane.showMessageDialog(null, "That was NOT a number!");
				}
					Double num1 = Double.parseDouble(num1str);
					
				while ((!operation.equals("q")) && (!operation.equals("Q")))
				{
					if ((!operation.equals("q")) && (!operation.equals("Q")))
					{
						operation = JOptionPane.showInputDialog(null, "Enter your operation: \n/ \n*\n+\n-\n (Q)uit");
						if ((!operation.equals("q")) && (!operation.equals("Q")))
						{
							String num2str = JOptionPane.showInputDialog(null, "Enter your next number:");
							Double num2 = Double.parseDouble(num2str);
							if (operation.equals("*"))
							{
								JOptionPane.showMessageDialog(null, num1 + operation + num2 + "=" + (num1 * num2));
								num1 = (num1 * num2);
							}
							if (operation.equals("/"))
							{
								JOptionPane.showMessageDialog(null, num1 + operation + num2 + "=" + (num1 / num2));
								num1 = (num1 / num2);
							}
							if (operation.equals("+"))
							{
								JOptionPane.showMessageDialog(null, num1 + operation + num2 + "=" + (num1 + num2));
								num1 = (num1 + num2);
								
							}
							if (operation.equals("-"))
							{
								
								JOptionPane.showMessageDialog(null, num1 + operation + num2 + "=" + (num1 - num2));
								num1 = (num1 - num2);
							}
						}
					}
				}
			}
		}
	}
	}
